package cn.qidisoft.edu.hzjt.service.zyc.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.qidisoft.core.common.code.QdfRespCode;
import cn.qidisoft.core.common.exception.dao.DBException;
import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.edu.hzjt.dao.SemesterMapper;
import cn.qidisoft.edu.hzjt.dao.zyc.DyxfzsMapper;
import cn.qidisoft.edu.hzjt.model.Semester;
import cn.qidisoft.edu.hzjt.model.zyc.PartyEvalItem;
import cn.qidisoft.edu.hzjt.model.zyc.PartyLeagueMember;
import cn.qidisoft.edu.hzjt.model.zyc.PartyMemberEvalScore;
import cn.qidisoft.edu.hzjt.model.zyc.PartyMemberEvaluation;
import cn.qidisoft.edu.hzjt.service.zyc.IDyxfzsService;
import cn.qidisoft.edu.hzjt.utils.LogType;

/**
 * 党员个人先锋指数业务层实现层
 * @author zhangwenliang
 * @Date 2018.11.24
 */
@Service
public class DyxfzsServiceImpl implements IDyxfzsService{
	protected static final LoggerAdapter LOGGER = LoggerAdapterFactory.getLogger(LogType.HZJT_LOGGER.val);
	@Autowired
	private DyxfzsMapper dyxfzsMapper;
	
	@Autowired
	private SemesterMapper semesterMapper; 
	
	@Override
	public PaginationBean<PartyEvalItem> getgradeListData(Map<String, Object> queryMap, Page page) {
		int c = dyxfzsMapper.getCounnts(queryMap);
		int totalRecords = 0;
		totalRecords = (int) c;
		PaginationBean<PartyEvalItem> pageHolder = new PaginationBean<PartyEvalItem>(page, totalRecords);
		List<PartyEvalItem> resultList = dyxfzsMapper.getgradeListData(queryMap,
				new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(), pageHolder.getPageSize()));
		pageHolder.setPageList(resultList);
		return pageHolder;
	}
	
	
	@Override
	public PaginationBean<PartyMemberEvaluation> getListData(Map<String, Object> queryMap, Page page) {
		int c = dyxfzsMapper.getCounnt(queryMap);
		int totalRecords = 0;
		totalRecords = (int) c;
		PaginationBean<PartyMemberEvaluation> pageHolder = new PaginationBean<PartyMemberEvaluation>(page, totalRecords);
		List<PartyMemberEvaluation> resultList = dyxfzsMapper.getListData(queryMap,
				new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(), pageHolder.getPageSize()));
		pageHolder.setPageList(resultList);
		return pageHolder;
	}
	
	@Override
    @Transactional
    public void delete(List<Integer> data) {
        try {
        	dyxfzsMapper.delete(data);
        } catch (Exception e) {
            LOGGER.error("delete [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }
	
	@Override
    @Transactional
    public void deletegrade(List<Integer> data) {
        try {
        	dyxfzsMapper.deletegrade(data);
        } catch (Exception e) {
            LOGGER.error("delete [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

	@Override
	public List<PartyMemberEvaluation> getDybList(Map<String, Object> queryMap) {
		return dyxfzsMapper.getDybList(queryMap);
	}


	@Override
	public void insertgarde(PartyEvalItem partyEvalItem) {
		dyxfzsMapper.insertgarde(partyEvalItem);
	}


	@Override
	public Semester queryByPK(Integer xqid) {
		return semesterMapper.queryByPK(xqid);
	}


	@Override
	public List<PartyEvalItem> getListGrade() {
		
		return dyxfzsMapper.getListGrade();
	}


	@Override
	public int updateDyxfzsinfo(PartyMemberEvaluation partyMemberEvaluation) {
		return dyxfzsMapper.updateDyxfzsinfo(partyMemberEvaluation);
	}
	@Override
	public PaginationBean<PartyLeagueMember> getdyGardeListData(Map<String, Object> queryMap, Page page) {
		int c = dyxfzsMapper.getCounntss(queryMap);
		int totalRecords = 0;
		totalRecords = (int) c;
		PaginationBean<PartyLeagueMember> pageHolder = new PaginationBean<PartyLeagueMember>(page, totalRecords);
		List<PartyLeagueMember> resultList = dyxfzsMapper.getdyGardeListData(queryMap,
				new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(), pageHolder.getPageSize()));
		pageHolder.setPageList(resultList);
		return pageHolder;
	}


	@Override
	public List<PartyMemberEvalScore> getScoreData(Integer getzSID) {
		
		return dyxfzsMapper.getScoreData(getzSID);
	}


	@Override
	public void insert(PartyMemberEvaluation pEvaluation) {
		dyxfzsMapper.insert(pEvaluation);
		
	}


	@Override
	public PartyMemberEvalScore selectScore(Map<String, Object> qMap) {
		return dyxfzsMapper.selectScore(qMap);
	}


	@Override
	public void updateScore(PartyMemberEvalScore pEvalScore) {
		dyxfzsMapper.updateScore(pEvalScore);
	}


	@Override
	public void insertScore(PartyMemberEvalScore pEvalScore) {
		dyxfzsMapper.insertScore(pEvalScore);
		
	}


	@Override
	public PartyMemberEvaluation selectEval(PartyMemberEvaluation pEvaluation) {
		return dyxfzsMapper.selectEval(pEvaluation);
	}


	@Override
	public List<PartyMemberEvalScore> getScoreList(Map<String, Object> qMap) {
		
		return dyxfzsMapper.getScoreList(qMap);
	}

}
